package com.school.controller;

import com.school.entity.UserInfo;
import com.school.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/UserInfo")
public class UserInfoController {
    @Autowired
    UserInfoService service;

    // HttpServletRequest request, HttpServletResponse response

    @ResponseBody
    @RequestMapping("/getInfo.do")
    public UserInfo getInfo(String user_phone) {
        UserInfo userInfo = service.selectOne(user_phone);
        return userInfo;
    }

    @ResponseBody
    @RequestMapping("/insertInfo.do")
    public int insertInfo(String user_phone, String user_name, String user_idcard, String user_sex) {
        UserInfo userInfo = new UserInfo(user_phone, user_name, user_idcard, user_sex);
        int i = service.insertOne(userInfo);
        System.out.println("插入i = " + i);
        return i;
    }

    @ResponseBody
    @RequestMapping("/updateInfo.do")
    public int updateInfo(String user_phone, String user_name, String user_idcard, String user_sex) {
        UserInfo userInfo = new UserInfo(user_phone, user_name, user_idcard, user_sex);
        int i = service.updateOne(userInfo);
        System.out.println("更新 = " + i);
        return i;
    }


}
